package com.zly.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.zly.entity.Absence;
import com.zly.entity.Dorm;
import com.zly.entity.Houseparent;
import com.zly.entity.StudentInfoManager;
import com.zly.service.DormService;
import com.zly.service.impl.DormServiceImpl;

import net.sf.json.JSONArray;

public class SelectAction extends ActionSupport {

	/**
	 * 反序列化
	 */
	private static final long serialVersionUID = 1L;

	private String result;
	private String result2;
	private String resultTower;
	private String resultAbs;

	public String getResultAbs() {
		return resultAbs;
	}

	public void setResultAbs(String resultAbs) {
		this.resultAbs = resultAbs;
	}

	public String getResultTower() {
		return resultTower;
	}

	public void setResultTower(String resultTower) {
		this.resultTower = resultTower;
	}

	public String getResult2() {
		return result2;
	}

	public void setResult2(String result2) {
		this.result2 = result2;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}
	/**
	 * 查询宿舍管理员
	 * @return
	 */
	public String selectDormManager() {
		// 调用service实现查找
		DormService<Houseparent> dormService = new DormServiceImpl<>();
		List<Houseparent> houseparents = dormService.select(Houseparent.class, "select * from houseparent");
		/*
		 * HttpServletRequest request = ServletActionContext.getRequest(); HttpSession
		 * session = request.getSession(); session.setAttribute("houseparents",
		 * houseparents);
		 */
		JSONArray json = JSONArray.fromObject(houseparents);
		result = json.toString();
		return SUCCESS;
	}
	/**
	 * 查询学生
	 * @return
	 */
	public String selectStu() {
		// 调用service实现查找
		DormService<StudentInfoManager> dormService = new DormServiceImpl<>();
		List<StudentInfoManager> studentInfoManagers = dormService.select(StudentInfoManager.class, "select * from studentinfomanager");
//		System.out.println(studentInfoManagers);
		JSONArray json = JSONArray.fromObject(studentInfoManagers);
		result2 = json.toString();
		return SUCCESS;
	}
	/**
	 * 查询宿舍楼
	 * @return
	 */
	public String selectTower() {
		// 调用service实现查找
		DormService<Dorm> dormService = new DormServiceImpl<>();
		List<Dorm> dorms = dormService.select(Dorm.class, "select * from dorm");
		System.out.println(dorms);
		JSONArray json = JSONArray.fromObject(dorms);
		resultTower = json.toString();
		return SUCCESS;
	}
	/**
	 * 查询考勤
	 * @return
	 */
	public String selectAbs() {
		// 调用service实现查找
		DormService<Absence> dormService = new DormServiceImpl<>();
		List<Absence> absences = dormService.select(Absence.class, "select * from absence");
		System.out.println(absences);
		JSONArray json = JSONArray.fromObject(absences);
		resultAbs = json.toString();
		return SUCCESS;
	}
}
